import numpy as np
import matplotlib.pyplot as plt

# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False


x = np.linspace(-5, 5, 1000)
x = x[np.abs(x) > 0.5]  # 排除0附近的值
y = x * np.log(np.e + 1/x**2)

plt.figure(figsize=(10, 6))
plt.plot(x, y, 'b-', label=r'$y = x·ln(e + 1/x^2)$', linewidth=2)
plt.plot(x, x, 'r--', label='斜渐近线 y=x', linewidth=2, alpha=0.7)
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.title('斜渐近线可视化验证', fontsize=14)
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()